package cc.lj.internal.coupons.infrastructure.repository.mysql;

import cc.lj.internal.core.exception.ServiceException;
import cc.lj.internal.core.model.BasePageHelper;
import cc.lj.internal.core.model.PageParam;
import cc.lj.internal.coupons.domain.ticket.repository.ITicketPackageBatchRepository;
import cc.lj.internal.coupons.infrastructure.dao.ITicketPackageBatchMapper;
import cc.lj.internal.coupons.infrastructure.excepion.CoupousExceptionEnum;
import cc.lj.internal.coupons.infrastructure.po.TicketPackageBatchPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 电子券包与批次关系表　mysql仓储实现
 * @author liangxifeng
 * @date 2023-08-23
 */
@Repository("ticketPackageBatchMysqlRespository")
public class TicketPackageBatchMysqlRespository implements ITicketPackageBatchRepository,BasePageHelper<TicketPackageBatchPO> {
    @Autowired
    private ITicketPackageBatchMapper mapper;

    @Override
    public List list(TicketPackageBatchPO entityPO) {
        QueryWrapper<TicketPackageBatchPO> wrapper = new QueryWrapper<>(entityPO);
        List<TicketPackageBatchPO> entitys = mapper.selectList(wrapper);
        return entitys;
    }

    @Override
    public Integer updateById(TicketPackageBatchPO entityPO) {
        Integer res = mapper.updateById(entityPO);
        if (res != 1)
        {
            throw new ServiceException(CoupousExceptionEnum.UPDATE_TICKET_PACKAGE_BATCH_FAILED);
        }
        return res;
    }

    @Override
    public TicketPackageBatchPO getById(Integer id) {
        TicketPackageBatchPO entityPO =  mapper.selectById(id);
        if(entityPO==null) {
            throw new ServiceException(CoupousExceptionEnum.TICKET_PACKAGE_BATCH_NOT_FOUND);
        }
        return entityPO;
    }

    @Override
    public PageInfo<TicketPackageBatchPO> selectPage(PageParam pageParam) {
        return this.page(pageParam);
    }


    @Override
    public List<TicketPackageBatchPO> getList(TicketPackageBatchPO ticketPackageBatchPO) {
        return this.list(ticketPackageBatchPO);
    }
}
